package com.gale.park.modules.pms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gale.park.common.api.CommonPage;
import com.gale.park.common.api.CommonResult;
import com.gale.park.common.service.RedisService;
import com.gale.park.modules.pms.dto.SeatConditionDTO;
import com.gale.park.modules.pms.model.PmsSeat;
import com.gale.park.modules.pms.service.PmsSeatService;
import io.swagger.annotations.ApiOperation;
import javafx.geometry.Pos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Gale
 * @since 2022-02-16
 */
@RestController
@RequestMapping("/seat")
public class PmsSeatController {

    @Autowired
    private PmsSeatService seatService;

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ApiOperation("添加车位")
    public CommonResult create(@RequestBody PmsSeat seat) {
        boolean result = seatService.create(seat);

        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation("获取车位列表,车位编号、所属区域")
    public CommonResult<CommonPage<PmsSeat>> list(@RequestBody SeatConditionDTO condition) {
        Page<PmsSeat> page = seatService.list(condition);

        return CommonResult.success(CommonPage.restPage(page));
    }

    @RequestMapping(value = "/getSeatInfo", method = RequestMethod.GET)
    @ApiOperation("获取车位,车位编号和id")
    public CommonResult getSeatInfo() {
       List<PmsSeat> list = seatService.list();
       return CommonResult.success(list);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @ApiOperation("通过id删除车位")
    public CommonResult delete(@PathVariable String id) {
        boolean result = seatService.deleteById(id);

        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }

    @RequestMapping(value = "/updateInfo/{id}", method = RequestMethod.POST)
    @ApiOperation("通过id获取要修改的车位信息")
    public CommonResult updateInfo(@PathVariable String id) {
        PmsSeat seat = seatService.updateInfo(id);

        return CommonResult.success(seat);
    }

    @RequestMapping(value = "/update/{seatId}", method = RequestMethod.POST)
    @ApiOperation("通过id获取要修改的车位信息")
    public CommonResult update(@RequestBody PmsSeat seat) {
        System.out.println(seat);
        boolean result = seatService.update(seat);

        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }


}

